<template>
  <div class="app-container">
    <SearchForm
      v-show="showSearch"
      v-model="queryParams"
      :options="options.formOps"
      @onQuery="getList"
      :showTime="true"
    >
    </SearchForm>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <Table
      ref="table"
      :auto-featch="true"
      :fetch-data="fetchData"
      :options="options.table"
      action-width="160"
    >
      <template #default>
        <el-table-column
          label="路线点位数"
          align="center"
          prop="sumCount"
          width="130"
        >
        </el-table-column>
        <el-table-column
          label="未巡检点位数"
          align="center"
          prop="surplusCount"
          width="130"
        >
        </el-table-column>
        <el-table-column
          label="上报隐患数量"
          align="center"
          prop="countHiddenInfo"
          width="120"
        >
          <template #default="{ row }">
            <el-button type="text" @click="openYh(row)">
              {{ row.countHiddenInfo }}
            </el-button>
          </template>
        </el-table-column>
      </template>
      <template #actionButton="{ row }">
        <el-button type="text" @click="handleDetail(row)">查看</el-button>
        <el-button type="text" @click="handleCheckMap(row)"
          >查看人员轨迹</el-button
        >
      </template></Table
    >
    <el-dialog v-model="outerVisible" width="90%" title="巡检任务详情">
      <Inner ref="inner" :parentNode="parentNode"></Inner>
    </el-dialog>
    <el-dialog v-model="yhVisible" width="90%" title="巡检隐患详情">
      <Yh ref="yhinner" :parentNode="parentNode"></Yh>
    </el-dialog>
    <MapDialog ref="map" :useButton="false" @close="closeMap"></MapDialog>
  </div>
</template>

<script setup>
import Table from "@/components/Table/index.vue";
import SearchForm from "@/components/searchForm/index";
import { apis as APIS } from "@/api/znxj/xjrw.js";
import formJson from "./components/options.json";
import { useAsyncData, useFormJsonNew } from "@/views/hooks/useAsyncData.js";
import Inner from "./components//inner.vue";
import Yh from "./components/yh.vue";
import MapDialog from "./components/map.vue";

const inner = ref();
const parentNode = ref({});
const outerVisible = ref(false);
const yhVisible = ref(false);
const handleDetail = (row) => {
  outerVisible.value = true;
  nextTick().then(() => {
    parentNode.value = row;
  });
};
const openYh = (row) => {
  yhVisible.value = true;
  nextTick().then(() => {
    parentNode.value = row;
  });
};
const { proxy } = getCurrentInstance();

const ops = useFormJsonNew(formJson, {
  sort: [],
  sortable: [],
});
const options = reactive({
  table: ops,
  formOps: ops.filter((i) =>
    [
      "routeCode",
      "routeName",
      "startTime",
      "endTime",
      "planTaskState",
    ].includes(i.prop)
  ),
});

const showSearch = ref(true);
const dialogVform = ref();
const table = ref();

const { fetchData, getList, queryParams, form, handleExport } = useAsyncData({
  APIS: {
    ...APIS,
    url: "/inspectionPlanTaskDetails/",
  },
  formJson,
  dialogVform,
  table,
  proxy,
});
const map = ref();
const showMap = ref(false);
const handleCheckMap = (row) => {
  showMap.value = true;
  APIS.position({ id: row.id }).then((res) => {
    map.value.open(res);
  });
};
const closeMap = () => {
  showMap.value = false;
};
</script>

<style lang="scss" scoped></style>
